using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;

namespace EditorExtension
{
    public class EditorWindowExample : EditorWindow
    {
        [MenuItem("EditorExtensions/02_IMGUI/01_Open IMGUIEditorWindowExample")]
        static void OpenEditorWindowExample()
        {
            var window = GetWindow<EditorWindowExample>();
			window.titleContent = new GUIContent("IMGUI 示例窗口"); // 必须设置标题
			window.Show();
        }

        enum GUIMode
        {
            GUILayout,
            GUI,
            EditorGUI,
            EditorGUILayout,
        }
        private GUIMode mCurrentGUIMode = GUIMode.GUI;
        enum PageId
        {
            Basic,
            Enabled,
            Rotate,
            Scale,
            Color,
        }
        private PageId mCurrentPageId;
        
        private void OnGUI()
        {
            mCurrentGUIMode = (GUIMode)GUILayout.Toolbar((int)mCurrentGUIMode, Enum.GetNames(typeof(GUIMode)));
            mCurrentPageId = (PageId)GUILayout.Toolbar((int)mCurrentPageId, Enum.GetNames(typeof(PageId)));
            switch (mCurrentPageId)
            {
                case PageId.Basic:
                    Basic();
                    break;
                case PageId.Enabled:
                    Enabled();
                    break;
                case PageId.Rotate:
                    Rotate();
                    break;
                case PageId.Scale:
                    Scale();
                    break;
                case PageId.Color:
                    Color();
                    break;
            }
        }

        private GUILayoutAPI mGUILayoutAPI = new GUILayoutAPI();
        private GUI_API mGUI_API = new GUI_API();
        private EditorGUI_API mEditorGUI_API = new EditorGUI_API();
        private EditorGUILayoutAPI mEditorGUILayoutAPI = new EditorGUILayoutAPI();
        
        private void Basic()
        {
            switch (mCurrentGUIMode)
            {
                case GUIMode.GUILayout:
                    mGUILayoutAPI.Draw();
                    break;
                case GUIMode.GUI:
                    mGUI_API.Draw();
                    break;
                case GUIMode.EditorGUI:
                    mEditorGUI_API.Draw();
                    break;
                case GUIMode.EditorGUILayout:
                    mEditorGUILayoutAPI.Draw();
                    break;
            }
        }


        #region Enabled
        private bool mEnabledInteractive = true;

        void Enabled()
        {
            mEnabledInteractive = GUILayout.Toggle(mEnabledInteractive, "是否可以交互");
            GUI.enabled = mEnabledInteractive;
            Basic();
        }
        #endregion
        
        #region Rotate
        private bool mOpenRotateEffect = false;

        void Rotate()
        {
            mOpenRotateEffect = GUILayout.Toggle(mOpenRotateEffect, "是否开启旋转效果");
            if (mOpenRotateEffect)
            {
                GUIUtility.RotateAroundPivot(45, new Vector2(100, 100));
            }
            Basic();
        }
        #endregion
        
        #region Scale
        private bool mOpenScaleEffect = false;
        void Scale()
        {
            mOpenScaleEffect = GUILayout.Toggle(mOpenScaleEffect, "是否开启缩放效果");
            if (mOpenScaleEffect)
            {
                GUIUtility.ScaleAroundPivot(new Vector2(0.5f, 0.7f), new Vector2(100, 100));
            }
            Basic();
        }
        #endregion

        #region Color
        
        private bool mOpenColorEffect = false;
        void Color()
        {
            mOpenColorEffect = GUILayout.Toggle(mOpenColorEffect, "变换颜色");
            if (mOpenColorEffect)
            {
                GUI.color = UnityEngine.Color.yellow;
            }
            Basic();
        }

        #endregion
    }
}
